$(function () {

    $("#jqGrid").jqGrid({
        url: '../servicesettlementmain/list',
        datatype: "json",
        colModel: [
            {label: 'id', name: 'id', index: 'id', key: true,hidden:true},
            {label: '结算点编号', name: 'settlementid', index: 'settlementid',hidden:true},
            {label: '年', name: 'year', index: 'year'},
            {label: '月', name: 'month', index: 'month'},
            {label: '批次', name: 'batch', index: 'batch'},
            {label: '实收总额', name: 'totalPaid', index: 'total_paid'},
            {label: '单位应缴工伤部分(应收)', name: 'dwyjGongsYs', index: 'dwyj_gongs_ys'},
            {label: '单位应缴养老部分(应收)', name: 'dwyjYanglYs', index: 'dwyj_yangl_ys'},
            {label: '单位应缴失业部分(应收)', name: 'dwyjShiyYs', index: 'dwyj_shiy_ys'},
            {label: '单位应缴医疗部分(应收)', name: 'dwyjYilYs', index: 'dwyj_yil_ys'},
            {label: '单位应缴生育部分(应收)', name: 'dwyjShengyYs', index: 'dwyj_shengy_ys'},
            {label: '单位应缴大病部分(应收)', name: 'dwyjDabYs', index: 'dwyj_dab_ys'},
            {label: '单位应缴公积金部分(应收)', name: 'dwyjGongjjYs', index: 'dwyj_gongjj_ys'},
            {label: '个人应缴养老部分(应收)', name: 'gryjYanglYs', index: 'gryj_yangl_ys'},
            {label: '个人应缴失业部分(应收)', name: 'gryjShiyYs', index: 'gryj_shiy_ys'},
            {label: '个人应缴医疗部分(应收)', name: 'gryjYilYs', index: 'gryj_yil_ys'},
            {label: '个人应缴大病部分(应收)', name: 'gryjDabYs', index: 'gryj_dab_ys'},
            {label: '个人应缴公积金部分(应收)', name: 'gryjGongjjYs', index: 'gryj_gongjj_ys'},
            {label: '结算单位收管理费(实收)', name: 'jsdwGuanlifSs', index: 'jsdw_guanlif_ss'},
            {label: '实收管理费人数', name: 'jsdwGuanlifSsRs', index: 'jsdw_guanlif_ss_rs'},
            {label: '结算单位收工资(实收)', name: 'jsdwSalarySs', index: 'jsdw_salary_ss'},
            {label: '实收工资人数', name: 'jsdwSalarySsRs', index: 'jsdw_salary_ss_rs'},
            {label: '结算单位收加班费(实收)', name: 'jsdwOvertimepaySs', index: 'jsdw_overtimepay_ss'},
            {label: '实收加班费人数', name: 'jsdwOvertimepaySsRs', index: 'jsdw_overtimepay_ss_rs'},
            {label: '结算单位工伤(实收)', name: 'jsdwGongsSs', index: 'jsdw_gongs_ss'},
            {label: '结算单位工商保险实收人数', name: 'jsdwGongsSsRs', index: 'jsdw_gongs_ss_rs'},
            {label: '结算单位养老(实收)', name: 'jsdwYanglSs', index: 'jsdw_yangl_ss'},
            {label: '结算单位养老费实收人数', name: 'jsdwYanglSsRs', index: 'jsdw_yangl_ss_rs'},
            {label: '结算单位失业(实收)', name: 'jsdwShiySs', index: 'jsdw_shiy_ss'},
            {label: '结算单位失业实收人数', name: 'jsdwShiySsRs', index: 'jsdw_shiy_ss_rs'},
            {label: '结算单位医疗(实收)', name: 'jsdwYilSs', index: 'jsdw_yil_ss'},
            {label: '结算单位医疗保险实收人数', name: 'jsdwYilSsRs', index: 'jsdw_yil_ss_rs'},
            {label: '结算单位生育(实收)', name: 'jsdwShengySs', index: 'jsdw_shengy_ss'},
            {label: '结算单位生育实收人数', name: 'jsdwShengySsRs', index: 'jsdw_shengy_ss_rs'},
            {label: '结算单位大病(实收)', name: 'jsdwDabSs', index: 'jsdw_dab_ss'},
            {label: '结算单位大病实收人数', name: 'jsdwDabSsRs', index: 'jsdw_dab_ss_rs'},
            {label: '结算单位公积金(实收)', name: 'jsdwGongjjSs', index: 'jsdw_gongjj_ss'},
            {label: '结算单位公积金实收人数', name: 'jsdwGongjjSsRs', index: 'jsdw_gongjj_ss_rs'},
            {label: '结算单位意外(实收)', name: 'jsdwYiwaiSs', index: 'jsdw_yiwai_ss'},
            {label: '结算单位意外实收人数', name: 'jsdwYiwaiSsRs', index: 'jsdw_yiwai_ss_rs'},
            {label: '结算单位单位小计(实收)', name: 'jsdwUnitsubtotalSs', index: 'jsdw_unitsubtotal_ss'},
            {label: '结算单位小计人数', name: 'jsdwUnitsubtotalSsRs', index: 'jsdw_unitsubtotal_ss_rs'},
            {label: '结算个人养老(实收)', name: 'jsgrYanglSs', index: 'jsgr_yangl_ss'},
            {label: '个人养老实收人数', name: 'jsgrYanglSsRs', index: 'jsgr_yangl_ss_rs'},
            {label: '结算个人失业(实收)', name: 'jsgrShiySs', index: 'jsgr_shiy_ss'},
            {label: '个人失业实收人数', name: 'jsgrShiySsRs', index: 'jsgr_shiy_ss_rs'},
            {label: '结算个人医疗(实收)', name: 'jsgrYilSs', index: 'jsgr_yil_ss'},
            {label: '个人医疗实收人数', name: 'jsgrYilSsRs', index: 'jsgr_yil_ss_rs'},
            {label: '结算个人生育(实收)', name: 'jsgrShengySs', index: 'jsgr_shengy_ss'},
            {label: '个人生育实收人数', name: 'jsgrShengySsRs', index: 'jsgr_shengy_ss_rs'},
            {label: '结算个人大病(实收)', name: 'jsgrDabSs', index: 'jsgr_dab_ss'},
            {label: '个人大病实收人数', name: 'jsgrDabSsRs', index: 'jsgr_dab_ss_rs'},
            {label: '结算个人公积金(实收)', name: 'jsgrGongjjSs', index: 'jsgr_gongjj_ss'},
            {label: '个人公积金实收人数', name: 'jsgrGongjjSsRs', index: 'jsgr_gongjj_ss_rs'},
            {label: '结算个人个人小计(实收)', name: 'jsgrPersonsubtotalSs', index: 'jsgr_personsubtotal_ss'},
            {label: '个人实收小计人数', name: 'jsgrPersonsubtotalSsRs', index: 'jsgr_personsubtotal_ss_rs'},
            {label: '单位补差工商', name: 'bcdwGongsYs', index: 'bcdw_gongs_ys'},
            {label: '单位补差养老', name: 'bcdwYanglYs', index: 'bcdw_yangl_ys'},
            {label: '单位补差失业', name: 'bcdwShiyYs', index: 'bcdw_shiy_ys'},
            {label: '单位补差医疗', name: 'bcdwYilYs', index: 'bcdw_yil_ys'},
            {label: '单位补差生育', name: 'bcdwShengyYs', index: 'bcdw_shengy_ys'},
            {label: '补差个人工伤', name: 'bcgrGongsYs', index: 'bcgr_gongs_ys'},
            {label: '补差个人养老', name: 'bcgrYanglYs', index: 'bcgr_yangl_ys'},
            {label: '补差个人失业', name: 'bcgrShiyYs', index: 'bcgr_shiy_ys'},
            {label: '补差个人生育', name: 'bcgrShengyYs', index: 'bcgr_shengy_ys'},
            {label: '补差个人医疗', name: 'bcgrYilYs', index: 'bcgr_yil_ys'},
            {label: '结算其他-各项保险社保补差(实收)', name: 'jsqtAllbxbcSs', index: 'jsqt_allbxbc_ss'},
            {label: '结算其他-个税(实收)', name: 'jsqtPersontaxSs', index: 'jsqt_persontax_ss'},
            {label: '结算其他-福利费(实收)', name: 'jsqtFulifSs', index: 'jsqt_fulif_ss'},
            {label: '结算其他-经济补偿(实收)', name: 'jsqtJingjibcSs', index: 'jsqt_jingjibc_ss'},
            {label: '结算其他-劳保用品(实收)', name: 'jsqtLaobaoSs', index: 'jsqt_laobao_ss'},
            {label: '结算其他-伙食(实收)', name: 'jsqtFoodSs', index: 'jsqt_food_ss'},
            {label: '结算其他-工伤费用(实收)', name: 'jsqtGongsSs', index: 'jsqt_gongs_ss'},
            {label: '结算其他-体检费用(实收)', name: 'jsqtTijianSs', index: 'jsqt_tijian_ss'},
            {label: '结算其他-税金(实收)', name: 'jsqtTaxSs', index: 'jsqt_tax_ss'},
            {label: '结算其他-社保补助(实收)', name: 'jsqtShebaobzSs', index: 'jsqt_shebaobz_ss'},
            {label: '结算其他-工会医疗互助(实收)', name: 'jsqtGonghyilSs', index: 'jsqt_gonghyil_ss'},
            {label: '结算其他-预留(实收)', name: 'jsqtRemarkoSs', index: 'jsqt_remarko_ss'},
            {label: '结算其他-预留(实收)', name: 'jsqtRemarktSs', index: 'jsqt_remarkt_ss'},
            {label: '结算其他-预留(实收)', name: 'jsqtRemarksSs', index: 'jsqt_remarks_ss'},
            {label: '结算其他-预留(实收)', name: 'jsqtRemarkfSs', index: 'jsqt_remarkf_ss'},
            {label: '结算其他-其他小计(实收)', name: 'jsqtSubtotalSs', index: 'jsqt_subtotal_ss'},
            {label: '结算其他-说明(实收)', name: 'jsqtExplainSs', index: 'jsqt_explain_ss'},
            {label: '基础信息-一审日期', name: 'basicFirstinstanceDate', index: 'basic_firstinstance_date'},
            {label: '基础信息-一审人', name: 'basicFirstinstancePerson', index: 'basic_firstinstance_person'},
            {label: '基础信息-二审日期', name: 'basicSecinstanceDate', index: 'basic_secinstance_date'},
            {label: '基础信息-二审人', name: 'basicSecinstancePerson', index: 'basic_secinstance_person'},
            {label: '结算其他-状态', name: 'basicStatus', index: 'basic_status'},
            {label: '结算其他-未清金额', name: 'basicOutstandingAmount', index: 'basic_outstanding_amount'},
            {label: '结算其他-税额', name: 'basicTaxAmount', index: 'basic_tax_amount'}
        ],
        viewrecords: true,
        height: 385,
        rowNum: 10,
        rowList: [10, 30, 50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth: true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        //字段太多自动加载横轴滚动条
        shrinkToFit: false,
        autoScroll: false,
        gridComplete: function () {
            //doResize();
            //显示grid底部滚动条
            //$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "scroll" });
            //隐藏grid底部滚动条
            //$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        title: null,
        serviceSettlementMain: {}
    },
    methods: {
        query: function () {
            vm.reload();
        },
        add: function () {

            vm.showList = false;
            vm.title = "新增";
            vm.serviceSettlementMain = {
                dwyjGongsYs: 200,
                jsdwGongsSsRs: 0,
                jsdwGongsSs: 0,

                gryjGongsYs: 200,
                jsgrGongsSsRs: 0,
                jsgrGongsSs: 0,
                //养老保险
                dwyjYanglYs: 200,
                jsdwYanglSsRs: 0,
                jsdwYanglSs: 0,

                gryjYanglYs: 200,
                jsgrYanglSsRs: 0,
                jsgrYanglSs: 0,
                //失业
                dwyjShiyYs: 200,
                jsdwShiySsRs: 0,
                jsdwShiySs: 0,
                gryjShiyYs: 30,
                jsgrShiySsRs: 0,
                jsgrShiySs: 0,
                //医疗 /....
                dwyjYilYs: 200,
                jsdwYilSsRs: 0,
                jsdwYilSs: 0,

                gryjYilYs: 200,
                jsgrYilSsRs: 0,
                jsgrYilSs: 0,
                //生育
                dwyjShengyYs: 200,
                jsdwShengySsRs: 0,
                jsdwShengySs: 0,

                gryjShengyYs: 200,
                jsgrShengySsRs: 0,
                jsgrShengySs: 0,

                //大病
                dwyjDabYs: 200,
                jsdwDabSsRs: 0,
                jsdwDabSs: 0,
                gryjDabYs: 200,
                jsgrDabSsRs: 0,
                jsgrDabSs: 0,

                //公积金
                dwyjGongjjYs: 200,
                jsdwGongjjSsRs: 0,
                jsdwGongjjSs: 0,
                gryjGongjjYs: 200,
                jsgrGongjjSsRs: 0,
                jsgrGongjjSs: 0,


            };
        },
        update: function (event) {
            var id = getSelectedRow();
            if (id == null) {
                return;
            }
            vm.showList = false;
            vm.title = "修改";

            vm.getInfo(id)
        },
        saveOrUpdate: function (event) {
            var url = vm.serviceSettlementMain.id == null ? "../servicesettlementmain/save" : "../servicesettlementmain/update";
            $.ajax({
                type: "POST",
                url: url,
                contentType: "application/json",
                data: JSON.stringify(vm.serviceSettlementMain),
                success: function (r) {
                    if (r.code === 0) {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
                    } else {
                        alert(r.msg);
                    }
                }
            });
        },
        del: function (event) {
            var ids = getSelectedRows();
            if (ids == null) {
                return;
            }

            confirm('确定要删除选中的记录？', function () {
                $.ajax({
                    type: "POST",
                    url: "../servicesettlementmain/delete",
                    contentType: "application/json",
                    data: JSON.stringify(ids),
                    success: function (r) {
                        if (r.code == 0) {
                            alert('操作成功', function (index) {
                                $("#jqGrid").trigger("reloadGrid");
                            });
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            });
        },
        Trial: function(type){
            var ids = getSelectedRows();
            if (ids == null) {
                return;
            }

            var params = new Object();
            params.ids = ids;
            params.type = type;
            $.ajax({
                type: "POST",
                url: "../servicesettlementmain/updateTrialStatus",
                contentType: "application/json",
                data: JSON.stringify(params),
                success: function (r) {
                    if (r.code == 0) {
                        alert('操作成功', function (index) {
                            $("#jqGrid").trigger("reloadGrid");
                        });
                    } else {
                        alert(r.msg);
                    }
                }
            });
        },
        getInfo: function (id) {
            $.get("../servicesettlementmain/info/" + id, function (r) {
                vm.serviceSettlementMain = r.serviceSettlementMain;

            });
        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                page: page
            }).trigger("reloadGrid");
        }
    },
    watch: {
        serviceSettlementMain: {
            handler: function (val, oldval) {
                //养老保险
                this.serviceSettlementMain.jsgrYanglSs = this.$refs.jsgrYanglSsRs.value * this.$refs.gryjYanglYs.value;
                this.serviceSettlementMain.jsdwYanglSs = this.$refs.jsdwYanglSsRs.value * this.$refs.dwyjYanglYs.value;
                //工伤
                this.serviceSettlementMain.jsdwGongsSs = this.$refs.dwyjGongsYs.value * this.$refs.jsdwGongsSsRs.value;
                //this.serviceSettlementMain.jsgrGongsSs = this.$refs.gryjGongsYs.value * this.$refs.jsgrGongsSsRs.value;
                //失业
                this.serviceSettlementMain.jsdwShiySs = this.$refs.jsdwShiySsRs.value * this.$refs.dwyjShiyYs.value;
                this.serviceSettlementMain.jsgrShiySs = this.$refs.jsgrShiySsRs.value * this.$refs.gryjShiyYs.value;
                //生育
                this.serviceSettlementMain.jsdwShengySs = this.$refs.dwyjShengyYs.value * this.$refs.jsdwShengySsRs.value;
                //this.serviceSettlementMain.jsgrShengySs = this.$refs.gryjShengyYs.value * this.$refs.jsgrShengySsRs.value;
                //大病
                this.serviceSettlementMain.jsgrDabSs = this.$refs.gryjDabYs.value * this.$refs.jsgrDabSsRs.value;
                this.serviceSettlementMain.jsdwDabSs = this.$refs.dwyjDabYs.value * this.$refs.jsdwDabSsRs.value;
                //医疗 /....
                this.serviceSettlementMain.jsdwYilSs = this.$refs.dwyjYilYs.value * this.$refs.jsdwYilSsRs.value;
                this.serviceSettlementMain.jsgrYilSs = this.$refs.gryjYilYs.value * this.$refs.jsgrYilSsRs.value;
                //公积金
                this.serviceSettlementMain.jsdwGongjjSs = this.$refs.dwyjGongjjYs.value * this.$refs.jsdwGongjjSsRs.value;
                this.serviceSettlementMain.jsgrGongjjSs = this.$refs.gryjGongjjYs.value * this.$refs.jsgrGongjjSsRs.value;
            },
            deep: true
        }
    },
});